Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
"El objeto posiblemente no está definido" cuando se usa Object.keys()

Tengo un problema con este fragmento de código y le aseguro a TypeScript que sé que la ubicación no estará indefinida (¿ya que estoy iterando a las Personas?).

En cada línea dentro de PeopleCard que Object is possibly 'undefined'.

Estoy un poco confundido como si el Objeto estuviera siendo iterado, asumo que no puede iterar

 {people && Object.keys(people).map((id: string) => ( <PeopleCard location={people[id]} onDelete={() => openDeletePeopleModal(locations[id])} onEdit={() => openEditPeopleDrawer(locations[id])} onClick={() => history.push(`/todo/${todo.id}/people/${people[id].id}`)} /> ))}

Obtengo people de mi Contexto y accedo a él así:

 let { people } = selectedTodo;

TypeScript cree que selectedTodo es del tipo ITodo y que las people son del tipo { [id: string]: Location } | undefined Lo cual me parece correcto.

Mis tipos son así:

 export type People = { id: string; peopleName: string; address1: string; address2?: string; address3?: string; address4?: string; address5?: string; town: string; postcode: string; country: string; } export type ITodo = { id: string; todoName: string; todoType: string; people?: { [id: string]: People }; };

Pensé que agregar otro cheque para indefinido podría sellar el trato, pero todo lo que he intentado hasta ahora no ha funcionado. ¡Solo puedo agregar ! después de cada uno, pero prefiero no hacerlo si es fácil de arreglar.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!